﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.MonoRail.Framework;
using Rodunu.Movies.Contracts;
using Rodunu.Movies.Interfaces.Subscriptions;
using Rodunu.Movies.Interfaces.User;
using Rodunu.Movies.Logic.Subscriptions;
using Rodunu.Movies.Logic.User;
using Rodunu.Movies.Services.Interfaces.Netflix;
using Rodunu.Movies.Services.NetFlix.Logic;

namespace Rodunu.Movies.Web.ViewComponents
{
    public class NetflixAtHomeComponent : ViewComponent
    {
        public override void Render()
        {
            long userId = Convert.ToInt64(Context.ComponentParameters["UserId"]);

            try
            {
                IUser userLogic = new UserLogic();
                UserInfo user = userLogic.Find(userId);
                ISubscriptions subscriptionsLogic = new SubscriptionsLogic();
                if (subscriptionsLogic.IsActiveService(user, ExternalServices.Netflix) && !String.IsNullOrEmpty(user.NetflixId))
                {
                    IManageAtHome manageAtHome = new ManageAtHome(user);
                    PropertyBag["AtHome"] = manageAtHome.GetMoviesAtHome(0);

                    IManageQueue manageQueue = new ManageQueue(user);
                    PropertyBag["Queue"] = manageQueue.GetUserQueue(0, 10);
                }
            }
            catch (Exception)
            {
            }

            base.Render();
        }
    }
}
